Se vazio será preenchido automaticamente."; $LANG["error_undeletable"] = "O elemento não pode ser apagado."; $LANG["creation_date"] = "Data Criação"; $LANG["modification_date"] = "Última Modificação"; $LANG["browse"] = "Escolher"; $LANG["manual_send"] = "Envio Manual"; $LANG["welcome"] = "Bem vindo"; $LANG["gotopage"] = "Ir para"; $LANG["pick_gmaps"] = "Escolher posição mapa"; $LANG["delete_gmaps"] = "Apagar posição"; $LANG["search_address"] = "Procurar Morada"; $LANG["keep_login"] = "Manter login"; ?> // \n"; } else { $output .= "\t\t\n"; } } } return $output; } function checkVerticalAlign($image_path, $height) { $size = getimagesize($image_path); return round(($height-$size[1])/2); } $GLOBALS['normalizeChars'] = array( 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f'); function buildShortURL($toClean) { //$toClean = strtolower(html_entity_decode($toClean,ENT_COMPAT, 'ISO-8859-1')); $toClean = strtolower($toClean); $toClean = str_replace('&', '-and-', $toClean); $toClean = strtr($toClean, $GLOBALS['normalizeChars']); $toClean = trim(preg_replace('/[^\w\d_ -]/si', '', $toClean)); $toClean = str_replace(' ', '-', $toClean); $toClean = str_replace('--', '-', $toClean); return $toClean; } ?>table = ""; $this->fieldcolumnssql = ""; $this->keycolumn = ""; $this->item = array(); $this->fieldcolumns = array(); $this->fieldtypes = array(); $this->fielddbtypes = array(); $this->fieldlabels = array(); $this->fieldattributes = array(); $this->fieldmandatory = array(); $this->fieldmaxchars = array(); $this->fieldminchars = array(); $this->fieldreadonly = array(); } public function setLang($lang) { self::$LANG = $lang; } public function loadRules($id, $title="") { global $CONNECTION; if($id == 0 && $title != "") { $com = "SELECT id, db_table, rule, rule_error FROM ay_schema WHERE title = ?"; $res = $CONNECTION->executeQuery($com, array($title)); } else { $com = "SELECT id, db_table, rule, rule_error FROM ay_schema WHERE id = ?"; $res = $CONNECTION->executeQuery($com, array($id)); } if($dbdata = $CONNECTION->getLine($res)) { //$dbdata = $CONNECTION->getLine($res); $this->id = $dbdata[0]; $this->_db_table = $dbdata[1]; $this->_rule = $dbdata[2]; $this->_rule_error = $dbdata[3]; } } public function checkRules($sql, $vars) { global $CONNECTION; $res = $CONNECTION->executeQuery($sql, $vars); return $CONNECTION->numRows($res); } public function load($id, $title="") { global $CONNECTION; if($id == 0 && $title != "") { $com = "SELECT id, title, db_table, fields_key, orderby_field, orderby_dir, multiselection, pagination, where_restriction, rule, rule_error, textarea_editor, list_buttons, list_permissions, global_buttons, global_permissions, details_buttons, details_permissions, panels FROM ay_schema WHERE title = ?"; $res = $CONNECTION->executeQuery($com, array($title)); } else { $com = "SELECT id, title, db_table, fields_key, orderby_field, orderby_dir, multiselection, pagination, where_restriction, rule, rule_error, textarea_editor, list_buttons, list_permissions, global_buttons, global_permissions, details_buttons, details_permissions, panels FROM ay_schema WHERE id = ?"; $res = $CONNECTION->executeQuery($com, array($id)); } //$n_rows = $CONNECTION->numRows($res); if($dbdata = $CONNECTION->getLine($res)) { //$dbdata = $CONNECTION->getLine($res); $this->id = $dbdata[0]; $this->_title = $dbdata[1]; $this->_db_table = $dbdata[2]; // s $this->_fields_key = $dbdata[3]; // s $this->_orderby_field = $dbdata[4]; // s2 $this->_orderby_dir = $dbdata[5]; // s2 $this->_multiselection = $dbdata[6]; // s2 $this->_pagination = $dbdata[7]; // s $this->_where_restriction = $dbdata[8]; // s2 $this->_rule = $dbdata[9]; // ? $this->_rule_error = $dbdata[10]; // ? $this->_textarea_editor = $dbdata[11]; // s2 $this->_list_buttons = $dbdata[12]; // s2 $this->_list_permissions = $dbdata[13]; // s2 $this->_global_buttons = $dbdata[14]; // s2 $this->_global_permissions = $dbdata[15]; // s2 $this->_details_buttons = $dbdata[16]; // s3 $this->_details_permissions = $dbdata[17]; // s3 if($dbdata[18] != "") { $panels_tmp = explode("#", $dbdata[18]); $this->_panels = array(); for($k = 0; $k < sizeof($panels_tmp); $k++) { $tmp = explode("|", $panels_tmp[$k]); array_push($this->_panels, array("id" => $tmp[0], "title" => $tmp[1])); } } $this->setDBTable($this->_db_table); $this->setTextAreaEditor($this->_textarea_editor); $this->setKeyColumn($this->_fields_key); $this->_restrictionfield = array(); $this->_restrictionvalue = array(); $this->_restrictionoperator = array(); if($this->_where_restriction != "") { $restriction_tmp = explode("#", $this->_where_restriction); $restriction_tmp_field = explode("|", $restriction_tmp[0]); $restriction_tmp_value = explode("|", $restriction_tmp[1]); $restriction_tmp_operator = explode("|", $restriction_tmp[2]); for($i=0; $i_restrictionfield, $restriction_tmp_field[$i]); $value = $restriction_tmp_value[$i]; if(substr($value, 0, 8) == "session=") $value = $_SESSION[MAYS_ID.substr($value, 8)]; array_push($this->_restrictionvalue, $value); array_push($this->_restrictionoperator, $restriction_tmp_operator[$i]!=""?$restriction_tmp_operator[$i]:"="); } } $com = "SELECT id, `column`, type, db_type, label, screen_order, mandatory, min_chars, max_chars, readonly, data_source, attributes, default_value, view_permission, list_percentage, filter_label, filter_operator, filter_advanced, `key`, panel FROM ay_fields WHERE schema_id = ? AND active = 1 AND view_permission <= ? ORDER BY screen_order ASC, id ASC"; if(!isset($_SESSION[MAYS_ID."_PROFILE_VIEW_PERMISSION"]) || $_SESSION[MAYS_ID."_PROFILE_VIEW_PERMISSION"] == "") $res = $CONNECTION->executeQuery($com, array($this->id, 9)); else $res = $CONNECTION->executeQuery($com, array($this->id, $_SESSION[MAYS_ID."_PROFILE_VIEW_PERMISSION"])); $n_rows = $CONNECTION->numRows($res); if($n_rows == 0) return false; $this->_column_array = array(); $this->_type_array = array(); $this->_db_type_array = array(); $this->_label_array = array(); $this->_mandatory_array = array(); $this->_min_chars_array = array(); $this->_max_chars_array = array(); $this->_readonly_array = array(); $this->_data_source_array = array(); $this->_list_percentage_array = array(); $this->_filter_label_array = array(); $this->_filter_operator_array = array(); $this->_filter_advanced_array = array(); $this->_keys_array = array(); $this->_panels_array = array(); for($i=0; $i != $n_rows ; $i++) { $dbdata = $CONNECTION->getLine($res); $id = $dbdata[0]; $column = $dbdata[1]; // s $type = $dbdata[2]; // s $db_type = $dbdata[3]; // s $label = $dbdata[4]; // s $screen_order = $dbdata[5]; // n $mandatory = $dbdata[6]; // s $min_chars = $dbdata[7]; // s $max_chars = $dbdata[8]; // s $readonly = $dbdata[9]; // s $data_source = $dbdata[10]; // s $attributes = $dbdata[11]; // s $default_value = $dbdata[12]; // ? $view_permission = $dbdata[13]; // n $list_percentage = $dbdata[14]; // s2 $filter_label = $dbdata[15]; // s2 $filter_operator = $dbdata[16]; // s2 $filter_advanced = $dbdata[17]; // s2 $key = $dbdata[18]; // s2 $panel = $dbdata[19]; // s2 if($type == "boolean") $data_source = "rs=0|" . self::$LANG["no"] . "#1|" . self::$LANG["yes"]; array_push($this->_column_array, $column); array_push($this->_type_array, $type); array_push($this->_db_type_array, $db_type); array_push($this->_label_array, $label); array_push($this->_mandatory_array, $mandatory); array_push($this->_min_chars_array, $min_chars); array_push($this->_max_chars_array, $max_chars); array_push($this->_readonly_array, $readonly); array_push($this->_data_source_array, $data_source); array_push($this->_list_percentage_array, $list_percentage); array_push($this->_filter_label_array, $filter_label); array_push($this->_filter_operator_array, $filter_operator); array_push($this->_filter_advanced_array, $filter_advanced); array_push($this->_panels_array, $panel); $this->_keys_array[$key] = $column; $attributes_array = array(); if($default_value != "") $attributes_array["default_value"] = $default_value; if($data_source != "") $attributes_array["data_source"] = $data_source; if($attributes != "") { $tmp = explode("&", $attributes); for($j=0; $j 0) $this->set($column, $attributes_array); } $this->setColumns($this->_column_array); $this->setTypes($this->_type_array); $this->setDBTypes($this->_db_type_array); $this->setLabels($this->_label_array); $this->setMandatory($this->_mandatory_array); $this->setMinchars($this->_min_chars_array); $this->setMaxchars($this->_max_chars_array); $this->setReadonly($this->_readonly_array); $this->setPanels($this->_panels_array); return true; } return false; } /** * Recebe o nome da tabela onde se vai obter os dados na base de dados. * * @access public * @param string $table nome da tabela da base de dados */ public function setDBTable($table) { $this->table = $table; } /** * Define o nome das colunas de Base de Dados que ser�o usadas para ir ler os dados * * @access public * @param array $columns Array com os nomes das colunas de Base de Dados. */ public function setColumns($columns) { $this->fieldcolumns = $columns; $this->fieldcolumnssql = ""; for($i=0; $i < sizeof($this->fieldcolumns); $i++ ) { if($this->fieldcolumns[$i] != "") { $this->fieldcolumnssql .= $this->fieldcolumns[$i]; } else { $this->fieldcolumns[$i] = "label" . $i . ""; $this->fieldcolumnssql .= "''"; } if($i < sizeof($this->fieldcolumns) - 1) $this->fieldcolumnssql .= ", "; } } public function setKeyColumn($keycolumn) { $this->keycolumn = $keycolumn; } /** * Recebe um array de tipos de dados que caracterizam os campos usados. Por exemplo: setTypes(array(AYGUIObject::$DATA_TEXT, ...). * * @access public * @param array $types array com os tipos de dados */ public function setTypes($types) { for($i=0; $ifieldcolumns); $i++) { $this->fieldtypes[$this->fieldcolumns[$i]] = $types[$i]; } } /** * Recebe um array identificador do tipo de dados da base de dados. Por exemplo: setDBTypes(array(AYGUIObject::$DB_TEXT, ...). * * @access public * @param array $dbtypes array com os tipos de dados */ public function setDBTypes($dbtypes) { for($i=0; $ifieldcolumns); $i++) { if($dbtypes[$i] == "") $dbtypes[$i] = self::$DB_TEXT; $this->fielddbtypes[$this->fieldcolumns[$i]] = $dbtypes[$i]; } } /** * Define o nome a apresentar gr�ficamente junto dos campos do formul�rio. * * @access public * @param array $fieldlabels Array com os t�tulos dos campos. */ public function setLabels($fieldlabels) { for($i=0; $ifieldcolumns); $i++) { $this->fieldlabels[$this->fieldcolumns[$i]] = $fieldlabels[$i]; } } /** * Define que campos devem ser obrigat�rios na submiss�o do registo * * @access public * @param array $mandatory Array de inteiros (0 ou 1) */ public function setMandatory($mandatory) { for($i=0; $ifieldcolumns); $i++) { if($mandatory[$i] != "" && $mandatory[$i] != null) $this->fieldmandatory[$this->fieldcolumns[$i]] = $mandatory[$i]; else $this->fieldmandatory[$this->fieldcolumns[$i]] = 0; } } /** * Define para cada campo, qual o n�mero m�ximo de caracteres suportado. O valor 0 (Zero) significa que o registo n�o ter� valida��o de m�ximo de caracteres. * * @access public * @param array $maxchars Array de inteiros (0 - n) */ public function setMaxchars($maxchars) { for($i=0; $ifieldcolumns); $i++) { if($maxchars[$i] != "" && $maxchars[$i] != null) $this->fieldmaxchars[$this->fieldcolumns[$i]] = $maxchars[$i]; else $this->fieldmaxchars[$this->fieldcolumns[$i]] = 0; } } /** * Define para cada campo, qual o n�mero m�nimo de caracteres necess�rio. O valor 0 (Zero) significa que o registo n�o ter� valida��o de m�nimo de caracteres. * * @access public * @param array $minchars Array de inteiros (0 - n) */ public function setMinchars($minchars) { for($i=0; $ifieldcolumns); $i++) { if($minchars[$i] != "" && $minchars[$i] != null) $this->fieldminchars[$this->fieldcolumns[$i]] = $minchars[$i]; else $this->fieldminchars[$this->fieldcolumns[$i]] = 0; } } /** * Define para cada campo, qual o n�mero m�nimo de caracteres necess�rio. O valor 0 (Zero) significa que o registo n�o ter� valida��o de m�nimo de caracteres. * * @access public * @param array $minchars Array de inteiros (0 - n) */ public function setReadonly($readonly) { for($i=0; $ifieldcolumns); $i++) { if($readonly[$i] != "" && $readonly[$i] != null) $this->fieldreadonly[$this->fieldcolumns[$i]] = $readonly[$i]; else $this->fieldreadonly[$this->fieldcolumns[$i]] = 0; } } public function setPanels($panel) { for($i=0; $ifieldcolumns); $i++) { if($panel[$i] != "" && $panel[$i] != null) $this->fieldpanels[$this->fieldcolumns[$i]] = $panel[$i]; else $this->fieldpanels[$this->fieldcolumns[$i]] = ""; } } /** * Define os atributos para um determinado elemento. Permite por exemplo configurar dados do tipo Combobox, onde s�o suportadas duas sintaxes: rs=0|Texto#1|Texto2 ou sql=SELECT id, name FROM table. * * @access public * @param string $fieldcolumn identificador da coluna * @param array $value Array com propriedades => valor dos v�rios atributos de um tipo */ public function set($fieldcolumn, $value) { $this->fieldattributes[$fieldcolumn] = $value; } /** * Define qual a variante do TinyMCE que deve ser inclu�da para todas as textfields * * @access public * @param string $editor String que define o tipo de TinyMCE (tinymcehtml/tinymceflash/tinymceflashlinks) */ public function setTextAreaEditor($editor) { $this->textareaeditor = $editor; } public function select($id) { global $CONNECTION; $restrictionvalues = array(); $restrictionsql = ""; if(sizeof($this->_restrictionfield) > 0) { for($i=0; $i_restrictionfield); $i++) { $restrictionsql .= " AND ".$this->_restrictionfield[$i]." ".($this->_restrictionoperator[$i]!=""?$this->_restrictionoperator[$i]:"="). " ?"; array_push($restrictionvalues, $this->_restrictionvalue[$i]); } } $com = "SELECT " . $this->fieldcolumnssql . " FROM " . $this->table . " WHERE " . $this->keycolumn . " = ?".$restrictionsql; $res = $CONNECTION->executeQuery($com, array_merge(array($id),$restrictionvalues)); $return_item = array(); if($tmp = $CONNECTION->getLine($res)) { for($i=0; $ifieldcolumns); $i++) { $return_item[array_search($this->fieldcolumns[$i], $this->_keys_array)] = $tmp[$i]; $this->item[$this->fieldcolumns[$i]] = $tmp[$i]; } } return $return_item; //$this->item; } public function selectFirst() { global $CONNECTION; $com = "SELECT " . $this->fieldcolumnssql . " FROM " . $this->table . " WHERE 1=1 "; $condition = ""; $conditionfield = $this->_restrictionfield; $conditionvalue = $this->_restrictionvalue; $conditionoperator = $this->_restrictionoperator; if(sizeof($conditionfield) > 0 && sizeof($conditionvalue) > 0 && sizeof($conditionoperator) > 0) { for($i=0; $iexecuteQuery($com, $conditionvalue); $n_rows = $CONNECTION->numRows($res); $return_item = array(); if($i == 1) { $tmp = $CONNECTION->getLine($res); for($i=0; $ifieldcolumns); $i++) { $return_item[array_search($this->fieldcolumns[$i], $this->_keys_array)] = $tmp[$i]; $this->item[$this->fieldcolumns[$i]] = $tmp[$i]; } } return $return_item; //$this->item; } public $pageresults; public $totalresults; public $currentpage; //Utilizada no Form de Detalhe de 1� nivel (s/ lista). C�digo suspeito poder� ter c�digo a mais public function selectAll($conditionfield=array(), $conditionvalue=array(), $conditionoperator=array(), $orderbyid="", $orderbydir="", $pageresults=0, $currentpage=1, $logicaloperator=array()) { global $CONNECTION; $com = "SELECT " . $this->fieldcolumnssql . " FROM " . $this->table . " WHERE 1 = 1"; $comcount = "SELECT count(*) FROM ".$this->table." WHERE 1 = 1"; $condition = ""; for($i=0; $i_keys_array[$conditionfield[$i]]; if($logicaloperator[$i] == "") $logicaloperator[$i] = "AND"; } for($i=0; $i_restrictionfield); $i++) { $opentag = "("; if($i>0) $opentag = ""; if($logicaloperator[sizeof($conditionfield)+$i] == "") $logicaloperator[sizeof($conditionfield)+$i] = "AND ".$opentag; else $logicaloperator[sizeof($conditionfield)+$i] = $logicaloperator[sizeof($conditionfield)+$i] . " AND ".$opentag; } $conditionfield = array_merge($conditionfield, $this->_restrictionfield); $conditionvalue = array_merge($conditionvalue, $this->_restrictionvalue); $conditionoperator = array_merge($conditionoperator, $this->_restrictionoperator); if(sizeof($conditionfield) > 0 && sizeof($conditionvalue) > 0) { for($i=0; $i_restrictionfield) > 0) { $com .= $condition . ")"; $comcount .= $condition . ")"; } else { $com .= $condition; $comcount .= $condition; } if($orderbyid == "") { $orderbyid = $this->_orderby_field; $orderbydir = $this->_orderby_dir; } if($orderbyid != "" && $orderbydir != "") { $ordertype = $this->fieldtypes[$orderbyid]; if($ordertype == AYSchema::$DATA_NUMBER) $com .= " ORDER BY CAST(".$orderbyid." AS SIGNED) ".$orderbydir; else if($ordertype == AYSchema::$DATA_DECIMAL) $com .= " ORDER BY (".$orderbyid."+0) ".$orderbydir; else $com .= " ORDER BY ".$orderbyid." ".$orderbydir; } //echo $com."|".print_r($conditionvalue, true); $res = $CONNECTION->executeQuery($comcount, $conditionvalue); $n_rows = $CONNECTION->getLine($res); $n_rows = $n_rows[0]; $this->pageresults = $pageresults; $this->currentpage = $currentpage; $this->totalresults = $n_rows; if($this->pageresults > 0) { $startposition = ($this->currentpage-1)*$this->pageresults; if($startposition >= $n_rows) { $this->currentpage = 1; $startposition = 0; } $this->totalpages = ceil($n_rows/$this->pageresults); $com .= " LIMIT " . $startposition . "," . $this->pageresults; } else $this->totalpages = 1; //echo $com."|".print_r($conditionvalue, true); $res = $CONNECTION->executeQuery($com, $conditionvalue); $n_rows = $CONNECTION->numRows($res); if($this->pageresults > 0) $n_rows = min($n_rows-$startposition, $this->pageresults); $itemresults = array(); for($i=0; $i<$n_rows; $i++) { $user_data = $CONNECTION->getLine($res); $dbitem = array(); for($j=0; $jfieldcolumns); $j++) { $dbitem[array_search($this->fieldcolumns[$j], $this->_keys_array)] = $user_data[$j]; } array_push($itemresults, $dbitem); } return $itemresults; } public function insert($values=array()) { global $CONNECTION; if(sizeof($values) > 0) { foreach($values as $key => $value) { $_POST[$this->table."_".$this->_keys_array[$key]] = $value; } $postvalues = $this->processPost(); // for files, when they are not upoaded, insert original value from post (for cases already processed) for($i=0; $ifieldcolumns); $i++) { $field = $this->fieldcolumns[$i]; $type = $this->fieldtypes[$field]; if(in_array($type, array(self::$DATA_VIDEO, self::$DATA_SWF, self::$DATA_MUSIC, self::$DATA_IMAGE, self::$DATA_FILE)) && $postvalues[$field] == "") { $postvalues[$field] = $values[array_search($field, $this->_keys_array)]; } } } else { $postvalues = $this->processPost(); } $fieldstmp = array(); $valuestmp = array(); $valuestmp2 = array(); //var_dump($this); for($i=0; $ifieldcolumns); $i++) { $field = $this->fieldcolumns[$i]; $type = $this->fieldtypes[$field]; $dbtype = $this->fielddbtypes[$field]; $readonly = $this->fieldreadonly[$field]; //$value = mysql_real_escape_string($postvalues[$field]); $value = $postvalues[$field]; if($type != self::$DATA_LABEL && $readonly != 2) { if($type == self::$DATA_HIDDEN && $value == "") { // ignore } else if(in_array($type, array(self::$DATA_VIDEO, self::$DATA_SWF, self::$DATA_MUSIC, self::$DATA_IMAGE, self::$DATA_FILE)) && $value == "delete") { // ignore } else { if($value == "") { array_push($fieldstmp, $field); array_push($valuestmp2, "null"); } else { array_push($fieldstmp, $field); array_push($valuestmp, $value); array_push($valuestmp2, "?"); } } } } if(AUDITORY_ACTIVE) { array_push($fieldstmp, "creator_username"); if($_SESSION[MAYS_ID."_USER_USERNAME"] != "") array_push($valuestmp, $_SESSION[MAYS_ID."_USER_USERNAME"]); else array_push($valuestmp, ""); array_push($valuestmp2, "?"); array_push($fieldstmp, "creator_timestamp"); array_push($valuestmp, time()); array_push($valuestmp2, "?"); array_push($fieldstmp, "editor_username"); if($_SESSION[MAYS_ID."_USER_USERNAME"] != "") array_push($valuestmp, $_SESSION[MAYS_ID."_USER_USERNAME"]); else array_push($valuestmp, ""); array_push($valuestmp2, "?"); array_push($fieldstmp, "editor_timestamp"); array_push($valuestmp, time()); array_push($valuestmp2, "?"); } $fields = join(", ",$fieldstmp); $values = join(", ", $valuestmp2); $com = "INSERT INTO ".$this->table." (".$fields.") VALUES (".$values.")"; $CONNECTION->executeQuery($com, $valuestmp); $this->item[$this->keycolumn] = $CONNECTION->getInsertID(); //echo $com . "::" . var_dump($valuestmp) . ":" . $this->item[0]; return $this->item[$this->keycolumn]; } public function update($instanceid, $values=array()) { global $CONNECTION; $this->select($instanceid); $maysmode = false; if(sizeof($values) == 0) { $maysmode = true; $values = $this->processPost($instanceid); } else { foreach($values as $key => $value) { $_POST[$this->table."_".$this->_keys_array[$key]] = $value; } $postvalues = $this->processPost($instanceid, $values); // for files, when they are not upoaded, insert original value from post (for cases already processed) for($i=0; $ifieldcolumns); $i++) { $field = $this->fieldcolumns[$i]; $type = $this->fieldtypes[$field]; if(in_array($type, array(self::$DATA_VIDEO, self::$DATA_SWF, self::$DATA_MUSIC, self::$DATA_IMAGE, self::$DATA_FILE)) && $postvalues[$field] == "") { $postvalues[$field] = $values[array_search($field, $this->_keys_array)]; } } $values = $postvalues; } $vars = array(); $update = ""; for($i=0; $ifieldcolumns); $i++) { $field = $this->fieldcolumns[$i]; $type = $this->fieldtypes[$field]; $readonly = $this->fieldreadonly[$field]; $currentvalue = $this->item[$field]; //$newvalue = mysql_real_escape_string($values[$field]); $newvalue = $values[$field]; if($maysmode || array_key_exists($field, $values)) { if($type != self::$DATA_HIDDEN && $type != self::$DATA_LABEL && $readonly == 0) { if($type == self::$DATA_IMAGELIST) { if($currentvalue != "") { $filelist = explode("#",$currentvalue); $newfilelist = explode("#",$newvalue); for($k=0; $kgetImageThumb($filelist[$k]); if(is_file(CONTENTS_EXTRA_PATH.$thumb)) unlink(CONTENTS_EXTRA_PATH.$thumb); } } } $update .= $field . " = ?, "; array_push($vars, $newvalue); } else if(in_array($type, array(self::$DATA_VIDEO, self::$DATA_SWF, self::$DATA_MUSIC, self::$DATA_IMAGE, self::$DATA_FILE))) { if($newvalue == "") { // ignore this, leave the one already uploaded } else { // check if any there before //echo $currentvalue; if($currentvalue != "") { if(is_file(CONTENTS_EXTRA_PATH.$currentvalue)) { unlink(CONTENTS_EXTRA_PATH.$currentvalue); $thumb = $this->getImageThumb($currentvalue); if(is_file(CONTENTS_EXTRA_PATH.$thumb)) unlink(CONTENTS_EXTRA_PATH.$thumb); } } if($newvalue == "" || $newvalue == "delete") { $update .= $field . " = null, "; } else { $update .= $field . " = ?, "; array_push($vars, $newvalue); } } } else if($type == self::$DATA_PASSWORD || $type == self::$DATA_PASSWORDMD5) { if($newvalue != "") { $update .= $field . " = ?, "; array_push($vars, $newvalue); } } else { if($newvalue == "") $update .= $field . " = null, "; else { $update .= $field . " = ?, "; array_push($vars, $newvalue); } } } } } if(AUDITORY_ACTIVE) { $update .= "editor_username = ?, "; array_push($vars, $_SESSION[MAYS_ID."_USER_USERNAME"]); $update .= "editor_timestamp = ?, "; array_push($vars, time()); } if(strlen($update) > 1) $update = substr($update, 0, strlen($update)-2); array_push($vars, $instanceid); $com = "UPDATE ".$this->table." SET ".$update." WHERE ".$this->keycolumn." = ?"; //echo $com."|".print_r($vars,true); $res = $CONNECTION->executeQuery($com, $vars); } private function processPost($instanceid="", $filter=array()) { $values = array(); for($i=0; $ifieldcolumns); $i++) { $field = $this->fieldcolumns[$i]; $fieldid = $this->table."_".$field; $type = $this->fieldtypes[$field]; $val = ""; $process = true; if(sizeof($filter) > 0) { if(array_key_exists(array_search($field, $this->_keys_array), $filter)) $process = true; else $process = false; } if($process) { if($type == self::$DATA_MEDIA) { $tmp = $_FILES[$fieldid]["name"]; if($tmp != "") { $tmparray = explode(".", $tmp); $tmpext = strtolower($tmparray[sizeof($tmparray)-1]); if($tmpext == "flv" || $tmpext == "mp4" || $tmpext == "f4v") $type = self::$DATA_VIDEO; else if($tmpext == "swf") $type = self::$DATA_SWF; else if($tmpext == "mp3") $type = self::$DATA_MUSIC; else $type = self::$DATA_IMAGE; } else { $type = self::$DATA_IMAGE; } $this->fieldtypes[$field] = $type; } if(in_array($type, array(self::$DATA_VIDEO, self::$DATA_SWF, self::$DATA_MUSIC, self::$DATA_FILE))) { $val = $this->processFileUpload($fieldid, $field); } else if($type == self::$DATA_IMAGE) { $val = $this->processImageUpload($fieldid, $field); } else if($type == self::$DATA_DATETIME) { $val = $this->processDateTime($fieldid); } else if($type == self::$DATA_TEXTAREA) { $val = $this->processTextArea($fieldid); } else if($type == self::$DATA_PASSWORDMD5) { $val = $this->processPasswordMD5($fieldid); } else if($type == self::$DATA_PRIORITY) { $val = $this->processPriority($fieldid, $field, $instanceid); } else if($type == self::$DATA_URLSEO) { $val = $this->processURLSEO($fieldid, $field, $instanceid); } else { //$val = htmlentities(returnReceivedVariable($fieldid), ENT_COMPAT, 'ISO-8859-1'); $val = returnReceivedVariable($fieldid); } if($instanceid == "" && $val == "") { if($this->fieldattributes[$field]["default_value"] != "") { $val = $this->processDefaultValue($this->fieldattributes[$field]["default_value"]); } } $values[$field] = $val; } else { if($instanceid == "" && $val == "") { if($this->fieldattributes[$field]["default_value"] != "") { $val = $this->processDefaultValue($this->fieldattributes[$field]["default_value"]); } } } } return $values; } public function processFileUploadValue($fieldid, $key) { return $this->processFileUpload($fieldid, $this->_keys_array[$key]); } private function processFileUpload($fieldid, $field) { if($_FILES[$fieldid]["name"] != "") { $name = $_FILES[$fieldid]["name"]; $size = $_FILES[$fieldid]["size"]; $array = explode(".", $name); $ext = strtolower(array_pop($array)); if(FILE_UPLOAD_NAME == "keepname") $name = strtolower(buildShortURL(join(".",$array))) . "." . $ext; else $name = time() . mt_rand(0, 9999) . "." . $ext; $valid_extensions = array("jpg", "jpeg", "gif", "png", "flv", "f4v", "mpeg", "mp4", "avi", "mp3", "ogg", "ogv", "webm", "zip", "doc", "docx", "xls", "xlsx", "pdf", "txt", "rtf", "ppt", "pptx", "pps", "ppsx", "swf"); if($size >1 && $size < MAX_UPLOAD && in_array($ext, $valid_extensions)) { $dir = "contents/".strtolower($this->_title)."/"; if(!is_dir(CONTENTS_EXTRA_PATH.$dir)) mkdir(CONTENTS_EXTRA_PATH.$dir,0777); $counter = 0; $filename = $dir . $name; while(file_exists(CONTENTS_EXTRA_PATH.$filename)) { if(FILE_UPLOAD_NAME == "keepname") $name = strtolower(buildShortURL(join(".",$array))) . "_" . mt_rand(0, 9999) . "." . $ext; else $name = time() . mt_rand(0, 9999) . "." . $ext; $filename = $dir . $name; $counter ++; if($counter > 10) break; } if(move_uploaded_file($_FILES[$fieldid]['tmp_name'], CONTENTS_EXTRA_PATH.$filename)) { chmod(CONTENTS_EXTRA_PATH.$filename, 0777); return $filename; } else { $_SESSION[MAYS_ID."error"] .= "" . self::$LANG["field"] . " " .$this->fieldlabels[$field].": " . self::$LANG["error_saving_file"]; return ""; } } else { $_SESSION[MAYS_ID."error"] .= "". self::$LANG["field"] . " " .$this->fieldlabels[$field].": " . self::$LANG["error_file_big"]; return ""; } } else { //$_SESSION[MAYS_ID."error"] .= "Campo ".$this->fieldlabels[$field].": o ficheiro nao existe. "; if(returnReceivedVariable($fieldid."auxfile") == "0") return "delete"; else return ""; } } public function processImageUploadValue($fieldid, $key) { return $this->processImageUpload($fieldid, $this->_keys_array[$key]); } private function processImageUpload($fieldid, $field) { $attribs = $this->fieldattributes[$field]; $fileext = isset($attribs["ext"]) && $attribs["ext"] != "" ? $attribs["ext"] : ""; $filewidth = isset($attribs["width"]) && $attribs["width"] != "" ? intval($attribs["width"]) : 0; $fileheight = isset($attribs["height"]) && $attribs["height"] != "" ? intval($attribs["height"]) : 0; $filetype = isset($attribs["type"]) && $attribs["type"] != "" ? $attribs["type"] : ""; $thumbactive = false; $thumbwidth = isset($attribs["thumbwidth"]) && $attribs["thumbwidth"] != "" ? intval($attribs["thumbwidth"]) : 0; $thumbheight = isset($attribs["thumbheight"]) && $attribs["thumbheight"] != "" ? intval($attribs["thumbheight"]) : 0; $thumbtype = isset($attribs["thumbtype"]) && $attribs["thumbtype"] != "" ? $attribs["thumbtype"] : ""; if($thumbwidth != 0 && $thumbheight != 0) { $thumbactive = true; } if($_FILES[$fieldid]["name"] != "") { $name = $_FILES[$fieldid]["name"]; $size = $_FILES[$fieldid]["size"]; $array = explode(".", $name); $ext = strtolower(array_pop($array)); if(FILE_UPLOAD_NAME == "keepname") $tmpname = strtolower(buildShortURL(join(".",$array))); else $tmpname = time() . mt_rand(0, 9999); $name = $tmpname . "." . $ext; $thumbname = $tmpname . "thumb." . $ext; $valid_extensions = array("jpg", "jpeg", "gif", "png"); if($size >1 && $size < MAX_UPLOAD && in_array($ext, $valid_extensions)) { try { $uploadedfile = $_FILES[$fieldid]['tmp_name']; if($ext == "jpg" || $ext == "jpeg") $src = imagecreatefromjpeg($uploadedfile); else if($ext == "gif") $src = imagecreatefromgif($uploadedfile); else if($ext == "png") $src = imagecreatefrompng($uploadedfile); if($src === FALSE) { $_SESSION[MAYS_ID."error"] .= "" . self::$LANG["field"] . " " .$this->fieldlabels[$field].": " . self::$LANG["error_file_information"]; return ""; } else { $dir = "contents/".strtolower($this->_title)."/"; if(!is_dir(CONTENTS_EXTRA_PATH.$dir)) mkdir(CONTENTS_EXTRA_PATH.$dir,0777); $counter = 0; $filename = $dir . $name; while(file_exists(CONTENTS_EXTRA_PATH.$filename)) { if(FILE_UPLOAD_NAME == "keepname") $tmpname = strtolower(buildShortURL(join(".",$array))) . "_" . mt_rand(0, 9999); else $tmpname = time() . mt_rand(0, 9999); $name = $tmpname . "." . $ext; $thumbname = $tmpname . "thumb." . $ext; $filename = $dir . $name; $counter ++; if($counter > 10) break; } $outputwidth = $filewidth; $outputheight = $fileheight; if($filetype == "crop") { list($width_orig, $height_orig) = getimagesize($uploadedfile); if($outputwidth == 0) $outputwidth = $width_orig; if($outputheight == 0) $outputheight = $height_orig; $ratio_orig = $width_orig/$height_orig; if ($outputwidth/$outputheight > $ratio_orig) { $new_height = $outputwidth/$ratio_orig; $new_width = $outputwidth; } else { $new_width = $outputheight*$ratio_orig; $new_height = $outputheight; } $x_mid = $new_width/2; //horizontal middle $y_mid = $new_height/2; //vertical middle $process = imagecreatetruecolor(round($new_width), round($new_height)); if($ext == "png") { imagealphablending($process, false); imagesavealpha($process, true); imagealphablending($src, true); imagesavealpha($src, true); } imagecopyresampled($process, $src, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); $tmp = imagecreatetruecolor($outputwidth, $outputheight); if($ext == "png") { imagealphablending($tmp, false); imagesavealpha($tmp, true); imagealphablending($src, true); imagesavealpha($src, true); } imagecopyresampled($tmp, $process, 0, 0, ($x_mid-($outputwidth/2)), ($y_mid-($outputheight/2)), $outputwidth, $outputheight, $outputwidth, $outputheight); imagedestroy($process); } else { list($width,$height) = getimagesize($uploadedfile); if($outputwidth == 0) $outputwidth = $width; if($outputheight == 0) $outputheight = $height; $widthscale = $width / $outputwidth; $heightscale = $height / $outputheight; $maxscale = max($widthscale, $heightscale); // preview other adjustments, like min/max/fixwidth/fixheight //$maxscale = min($widthscale, $heightscale); //$maxscale = $widthscale; // override, must have always 210 //$maxscale = $heightscale; // override, must have always 205 if($maxscale > 1) { $newwidth = $width / $maxscale; $newheight = $height / $maxscale; } else { $newwidth = $width; $newheight = $height; } $tmp = imagecreatetruecolor($newwidth,$newheight); if($ext == "png") { imagealphablending($tmp, false); imagesavealpha($tmp, true); imagealphablending($src, true); imagesavealpha($src, true); } imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); } if($ext == "jpg" || $ext == "jpeg") imagejpeg($tmp,CONTENTS_EXTRA_PATH.$filename,JPEG_QUALITY); else if($ext == "gif") imagegif($tmp,CONTENTS_EXTRA_PATH.$filename); else if($ext == "png") imagepng($tmp,CONTENTS_EXTRA_PATH.$filename,PNG_QUALITY); imagedestroy($tmp); if(file_exists(CONTENTS_EXTRA_PATH.$filename)) { chmod(CONTENTS_EXTRA_PATH.$filename, 0777); if($thumbactive) { if($thumbtype == "crop") { list($width_orig, $height_orig) = getimagesize($uploadedfile); $ratio_orig = $width_orig/$height_orig; if ($thumbwidth/$thumbheight > $ratio_orig) { $new_height = $thumbwidth/$ratio_orig; $new_width = $thumbwidth; } else { $new_width = $thumbheight*$ratio_orig; $new_height = $thumbheight; } $x_mid = $new_width/2; //horizontal middle $y_mid = $new_height/2; //vertical middle $process = imagecreatetruecolor(round($new_width), round($new_height)); if($ext == "png") { imagealphablending($process, false); imagesavealpha($process, true); imagealphablending($src, true); imagesavealpha($src, true); } imagecopyresampled($process, $src, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); $tmp = imagecreatetruecolor($thumbwidth, $thumbheight); if($ext == "png") { imagealphablending($tmp, false); imagesavealpha($tmp, true); imagealphablending($src, true); imagesavealpha($src, true); } imagecopyresampled($tmp, $process, 0, 0, ($x_mid-($thumbwidth/2)), ($y_mid-($thumbheight/2)), $thumbwidth, $thumbheight, $thumbwidth, $thumbheight); imagedestroy($process); } else { $outputwidth = $thumbwidth; $outputheight = $thumbheight; list($width,$height) = getimagesize($uploadedfile); $widthscale = $width / $outputwidth; $heightscale = $height / $outputheight; $maxscale = max($widthscale, $heightscale); if($maxscale > 1) { $newwidth = $width / $maxscale; $newheight = $height / $maxscale; } else { $newwidth = $width; $newheight = $height; } $tmp = imagecreatetruecolor($newwidth,$newheight); if($ext == "png") { imagealphablending($tmp, false); imagesavealpha($tmp, true); imagealphablending($src, true); imagesavealpha($src, true); } imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); } $filenamethumb = $dir . $thumbname; if($ext == "jpg" || $ext == "jpeg") imagejpeg($tmp,CONTENTS_EXTRA_PATH.$filenamethumb,JPEG_QUALITY); else if($ext == "gif") imagegif($tmp,CONTENTS_EXTRA_PATH.$filenamethumb); else if($ext == "png") imagepng($tmp,CONTENTS_EXTRA_PATH.$filenamethumb,PNG_QUALITY); imagedestroy($tmp); chmod(CONTENTS_EXTRA_PATH.$filenamethumb, 0777); } imagedestroy($src); return $filename; } else { $_SESSION[MAYS_ID."error"] .= "". self::$LANG["field"] . " " .$this->fieldlabels[$field].": " . self::$LANG["error_saving_file"]; return ""; } } //ob_clean(); } catch(Exception $error) { $_SESSION[MAYS_ID."error"] .= "". self::$LANG["field"] . " " .$this->fieldlabels[$field].": " . self::$LANG["error_converting_file"]; //ob_clean(); return ""; } } else { $_SESSION[MAYS_ID."error"] .= "" . self::$LANG["field"] . " " .$this->fieldlabels[$field].": " . self::$LANG["error_file_big"]; return ""; } } else { //$_SESSION[MAYS_ID."error"] .= "Campo ".$this->fieldlabels[$field].": o ficheiro nao existe. "; if(returnReceivedVariable($fieldid."auxfile") == "0") return "delete"; else return ""; } } private function processDateTime($fieldid) { if(returnReceivedVariable($fieldid."date") != "") return returnReceivedVariable($fieldid."date") . " " . returnReceivedVariable($fieldid); else return returnReceivedVariable($fieldid); } private function processTextArea($fieldid) { $msg = htmlentities(returnReceivedVariable($fieldid), ENT_COMPAT, 'UTF-8'); $msg = preg_replace("/amp;/","",$msg); $start = strpos($msg, "<!--"); $end = strpos($msg, "-->", $start); $counter = 0; while($start !== false && $end !== false && $counter < 20) { $msg = substr($msg, 0, $start) . substr($msg, ($end+6)); $start = strpos($msg, "<!--"); $end = strpos($msg, "-->", $start); $counter ++; } if($this->textareaeditor == "flash" || $this->textareaeditor == "flashlinks") { $msg = trim($msg); //$msg = stripslashes($msg); $msg = preg_replace("/font-(.*?);/","",$msg); $msg = preg_replace("/color:(.*?);/","",$msg); $msg = preg_replace("/mso-ansi-language:(.*?);/","",$msg); $msg = preg_replace("/<span style="text-decoration: underline;">(.*?)<\/span>/","<u>$1</u>",$msg); $msg = preg_replace("/ style="(.*?)"/","",$msg); $pos = strpos($msg, "<span>"); $counter = 0; while($pos !== false && $counter < 50) { $msg = preg_replace("/<span>(.*?)<\/span>/","$1",$msg); $pos = strpos($msg, "<span>"); $counter ++; } //$msg = str_replace("<p></p>", "", $msg); //$msg = str_replace("<p> </p>", "", $msg); //$msg = str_replace("'", "\'", $msg); // Retirar espa�os em branco no in�cio/fim for($z=0; $z<5; $z++) { if(substr($msg, 0, 25) == "<p> </p>") $msg = substr($msg, 25); if(substr($msg, strlen($msg)-25, strlen($msg)) == "<p> </p>") $msg = substr($msg, 0, strlen($msg)-25); $msg = trim($msg); } } $msg = html_entity_decode($msg, ENT_COMPAT, 'UTF-8'); return $msg; } private function processPasswordMD5($fieldid) { $pwd = returnReceivedVariable($fieldid); if($pwd != "") return md5($pwd); else return ""; } private function processPriority($fieldid, $field, $priorityid) { $priorityvalue = htmlentities(returnReceivedVariable($fieldid), ENT_COMPAT, 'UTF-8'); if($priorityid == "") $priorityid = -1; global $CONNECTION; $restrictionvalues = array(); $restrictionsql = ""; if(sizeof($this->_restrictionfield) > 0) { for($i=0; $i_restrictionfield); $i++) { $restrictionsql .= " AND ".$this->_restrictionfield[$i]." ".($this->_restrictionoperator[$i]!=""?$this->_restrictionoperator[$i]:"="). " ?"; array_push($restrictionvalues, $this->_restrictionvalue[$i]); } } $com = "SELECT ".$this->keycolumn." FROM ".$this->table." WHERE ".$this->keycolumn." <> ? AND ".$field." = ?".$restrictionsql; $res = $CONNECTION->executeQuery($com, array_merge(array($priorityid, $priorityvalue),$restrictionvalues)); $n_rows = $CONNECTION->numRows($res); //echo $com; if($n_rows > 0) { $com = "UPDATE ".$this->table." SET ".$field." = CAST(".$field." AS SIGNED) + 1 WHERE CAST(".$field." AS SIGNED) >= ?".$restrictionsql; $CONNECTION->executeQuery($com, array_merge(array($priorityvalue),$restrictionvalues)); } return $priorityvalue; } private function processURLSEO($fieldid, $field, $instanceid) { $val = htmlentities(returnReceivedVariable($fieldid), ENT_COMPAT, 'UTF-8'); $manual = true; if($val == "") { $manual = false; $val = $this->createURLSEO($field, $instanceid, false); } else $val = strtolower($val); for($i=0; $i<10; $i++) { if(!$this->checkUniqueURLSEO($field, $val, $instanceid)) { if($manual) { $val = $this->createURLSEO($field, $instanceid, false); $manual = false; } else $val = $this->createURLSEO($field, $instanceid, true); } else break; } return $val; } private function createURLSEO($field, $instanceid, $makeunique) { $datasrc = $this->fieldattributes[$field]["data_source"]; if(strpos($datasrc, "fields=") === 0) { $fieldids_tmp = substr($datasrc, 7); $fieldids = explode("#",$fieldids_tmp); $values = array(); if($makeunique) { if($instanceid != "") array_push($values, $instanceid); else array_push($values, rand(100,999)); } for($i=0; $itable."_".$fieldids[$i]; //$val = htmlentities(returnReceivedVariable($fieldid), ENT_COMPAT, 'UTF-8'); $val = returnReceivedVariable($fieldid); if($val != "") array_push($values, $val); } $finalval = strtolower(join("-",$values)); $finalval = buildShortURL($finalval); $maxchars = $this->fieldmaxchars[$field]; if($maxchars != 0) $finalval = substr($finalval, 0, $maxchars); return $finalval; } else { return ""; } } private function checkUniqueURLSEO($field, $val, $instanceid) { if($instanceid == "") $instanceid = -1; global $CONNECTION; $restrictionvalues = array(); $restrictionsql = ""; if(sizeof($this->_restrictionfield) > 0) { for($i=0; $i_restrictionfield); $i++) { $restrictionsql .= " AND ".$this->_restrictionfield[$i]." ".($this->_restrictionoperator[$i]!=""?$this->_restrictionoperator[$i]:"="). " ?"; array_push($restrictionvalues, $this->_restrictionvalue[$i]); } } $com = "SELECT ".$this->keycolumn." FROM ".$this->table." WHERE ".$this->keycolumn." <> ? AND ".$field." = ?".$restrictionsql; $res = $CONNECTION->executeQuery($com, array_merge(array($instanceid, $val),$restrictionvalues)); $n_rows = $CONNECTION->numRows($res); if($n_rows > 0) return false; else return true; } public function deleteAll() { $items = $this->selectAll(); for($i=0; $idelete($items[$i][$this->keycolumn]); } } public function delete($id) { $this->select($id); $delete_val = $this->item["deletable"]; if($delete_val == "0") { $_SESSION[MAYS_ID."error"] .= self::$LANG["error_undeletable"]; return; } global $CONNECTION; for($i=0; $ifieldcolumns); $i++) { $field = $this->fieldcolumns[$i]; $type = $this->fieldtypes[$field]; $val = $this->item[$field]; if($val != "") { if(in_array($type, array(self::$DATA_IMAGE,self::$DATA_FILE,self::$DATA_MUSIC,self::$DATA_VIDEO,self::$DATA_SWF,self::$DATA_MEDIA))) { $this->deleteImage($val); } else if($type == self::$DATA_IMAGELIST) { $imgs = explode("#",$val); for($j=0; $jdeleteImage($imgs[$j]); } } } if($type == self::$DATA_SCHEMA) { $datasrc = $this->fieldattributes[$field]["data_source"]; $cascade = $this->fieldattributes[$field]["cascade"]; if(strpos($datasrc, "schema=") === 0) { $subschemaid = substr($datasrc, 7); $subschema = new AYSchema(); $subschema->load($subschemaid); if($cascade == "setnull") { $com = "UPDATE ".$subschema->table." SET parent_id = null, parent_schema_id = null, parent_column = null WHERE parent_id = ? AND parent_column = ?"; //echo $com; $CONNECTION->executeQuery($com, array($id,$field)); } else { $com = "SELECT id FROM ".$subschema->table." WHERE parent_id = ? AND parent_column = ?"; $res = $CONNECTION->executeQuery($com, array($id,$field)); $n_rows = $CONNECTION->numRows($res); //echo "tem sub-schema para apagar no ".$id."|".$field." (".$subschemaid."-".$cascade.") ".$n_rows."
"; for($j=0; $j<$n_rows; $j++) { $user_data = $CONNECTION->getLine($res); $subid = $user_data[0]; $subschema->delete($subid); } } } } } $com = "DELETE FROM ".$this->table." WHERE ".$this->keycolumn." = ?"; //echo $com."|".$id."
"; $CONNECTION->executeQuery($com, array($id)); } public function getImageThumb($img) { $index = strrpos($img, "."); return substr($img, 0, $index) . "thumb" . substr($img,$index); } public function getElement($key) { return $this->item[$this->_keys_array[$key]]; } public function setElement($key, $value) { $this->item[$this->_keys_array[$key]] = $value; } public function getColumnFromKey($key) { return $this->_keys_array[$key]; } private function deleteImage($img) { if(is_file(CONTENTS_EXTRA_PATH.$img)) unlink(CONTENTS_EXTRA_PATH.$img); $thumb = $this->getImageThumb($img); if(is_file(CONTENTS_EXTRA_PATH.$thumb)) unlink(CONTENTS_EXTRA_PATH.$thumb); } /** * Adiciona um conjunto de restri��es a efectuar na pesquisa � base de dados, para restringir os resultados. * * @access public * @param array $restrictionfield array de strings com os atributos a restringir * @param array $restrictionvalue array de strings com os valores a comparar para cada atributo * @param array $restrictionoperator array de strings com os operadores a utilizar na compara��o (=/<>/IN/...) */ public function addWhereRestriction($restrictionfield, $restrictionvalue, $restrictionoperator) { $this->_restrictionfield = array_merge($this->_restrictionfield, $restrictionfield); $this->_restrictionvalue = array_merge($this->_restrictionvalue, $restrictionvalue); $this->_restrictionoperator = array_merge($this->_restrictionoperator, $restrictionoperator); } public function setAllColumnsListVisible() { for($i = 0; $i < sizeof($this->_list_percentage_array); $i++) { $this->_list_percentage_array[$i] = 1; } } public function processSQLKeywords($input) { $res = 0; preg_match_all("/\[(.+?)\]/", $input, $res); for($i=0; $igetColumnFromKey($field); $datasrc = $this->fieldattributes[$field]["data_source"]; $val = $value; if(strpos($datasrc, "rs=") === 0) { $rs = substr($datasrc, 3); $rs_array = explode("#", $rs); for($k=0; $kexecuteQuery($com, array($fathertriggerval)); $n_rows = $CONNECTION->numRows($res); for($k=0; $k < $n_rows; $k++) { $sql_val = $CONNECTION->getLine($res); if($sql_val[0] == $val) { return $sql_val[1]; } } } return ""; } } ?> :: BioBrotar ::